package cn.xscrum.demo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.demo.domain.SepDegree;
import cn.xscrum.demo.service.ISepDegreeService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 学位点信息Controller
 * 
 * @author xscrum
 * @date 2020-11-17
 */
@Controller
@RequestMapping("/demo/degree")
public class SepDegreeController extends BaseController
{
    private String prefix = "demo/degree";

    @Autowired
    private ISepDegreeService sepDegreeService;

    @RequiresPermissions("demo:degree:view")
    @GetMapping()
    public String degree()
    {
        return prefix + "/degree";
    }

    /**
	 * 查询学位点信息列表
     */
    @RequiresPermissions("demo:degree:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SepDegree sepDegree)
    {
        startPage();
        List<SepDegree> list = sepDegreeService.selectSepDegreeList(sepDegree);
        return getDataTable(list);
    }

    /**
	 * 导出学位点信息列表
     */
    @RequiresPermissions("demo:degree:export")
    @Log(title = "学位点信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SepDegree sepDegree)
    {
        List<SepDegree> list = sepDegreeService.selectSepDegreeList(sepDegree);
        ExcelUtil<SepDegree> util = new ExcelUtil<SepDegree>(SepDegree.class);
        return util.exportExcel(list, "degree");
    }

    /**
	 * 新增学位点信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存学位点信息
     */
    @RequiresPermissions("demo:degree:add")
    @Log(title = "学位点信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SepDegree sepDegree)
    {
        return toAjax(sepDegreeService.insertSepDegree(sepDegree));
    }

    /**
	 * 修改学位点信息
     */
    @GetMapping("/edit/{degreeId}")
    public String edit(@PathVariable("degreeId") String degreeId, ModelMap mmap)
    {
        SepDegree sepDegree = sepDegreeService.selectSepDegreeById(degreeId);
        mmap.put("sepDegree", sepDegree);
        return prefix + "/edit";
    }

    /**
	 * 修改保存学位点信息
     */
    @RequiresPermissions("demo:degree:edit")
    @Log(title = "学位点信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SepDegree sepDegree)
    {
        return toAjax(sepDegreeService.updateSepDegree(sepDegree));
    }

    /**
	 * 删除学位点信息
     */
    @RequiresPermissions("demo:degree:remove")
    @Log(title = "学位点信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sepDegreeService.deleteSepDegreeByIds(ids));
    }
}
